const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('SysUser', {
    userId: {
      field: 'user_id',
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: "用户ID"
    },
    deptId: {
      field: 'dept_id',
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: "部门ID"
    },
    loginName: {
      field: 'login_name',
      type: DataTypes.STRING(30),
      allowNull: false,
      comment: "登录账号"
    },
    userName: {
      field: 'user_name',
      type: DataTypes.STRING(30),
      allowNull: true,
      defaultValue: "",
      comment: "用户昵称"
    },
    userType: {
      field: 'user_type',
      type: DataTypes.STRING(2),
      allowNull: true,
      defaultValue: "00",
      comment: "用户类型（00系统用户 01注册用户）"
    },
    email: {
      type: DataTypes.STRING(50),
      allowNull: true,
      defaultValue: "",
      comment: "用户邮箱"
    },
    phoneNumber: {
      field: 'phone_number',
      type: DataTypes.STRING(11),
      allowNull: true,
      defaultValue: "",
      comment: "手机号码"
    },
    sex: {
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "0",
      comment: "用户性别（0男 1女 2未知）"
    },
    avatar: {
      type: DataTypes.STRING(100),
      allowNull: true,
      defaultValue: "",
      comment: "头像路径"
    },
    password: {
      type: DataTypes.STRING(50),
      allowNull: true,
      defaultValue: "",
      comment: "密码"
    },
    salt: {
      type: DataTypes.STRING(20),
      allowNull: true,
      defaultValue: "",
      comment: "盐加密"
    },
    status: {
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "0",
      comment: "帐号状态（0正常 1停用）"
    },
    delFlag: {
      field: 'del_flag',
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "0",
      comment: "删除标志（0代表存在 2代表删除）"
    },
    lastLoginIp: {
      field: 'last_login_ip',
      type: DataTypes.STRING(128),
      allowNull: true,
      defaultValue: "",
      comment: "最后登录IP"
    },
    lastLoginDate: {
      field: 'last_login_date',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "最后登录时间"
    },
    pwdLastUpdateDate: {
      field: 'pwd_last_update_date',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "密码最后更新时间"
    },
    createdBy: {
      field: 'create_by',
      type: DataTypes.STRING(64),
      allowNull: true,
      defaultValue: "",
      comment: "创建者"
    },
    createdAt: {
      field: 'create_time',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "创建时间"
    },
    updatedBy: {
      field: 'update_by',
      type: DataTypes.STRING(64),
      allowNull: true,
      defaultValue: "",
      comment: "更新者"
    },
    updatedAt: {
      field: 'update_time',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "更新时间"
    },
    remark: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: "备注"
    }
  }, {
    sequelize,
    tableName: 'sys_user',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        // 将数据库字段的下划线命名格式转换为驼峰命名格式
        underscored: true,
        fields: [
          { name: "user_id" },
        ]
      },
    ]
  });
};
